/*******************************************************************************

This code file produces Figure A25, "Citywide Estimates Under Alternative Discount Rate Assumptions."

*******************************************************************************/

*** Manage settings

	run "$dir/code/modules/settings.do"
	
********************************************************************************
* Complete table analysis
********************************************************************************

*** Initialize blank tempfile

	tempfile tmp
	set obs 1
	gen beta = .
	gen mcost = .
	gen elast = .
	save `tmp', replace

*** Loop
	
	forvalues beta = 0.90(0.0025)1 {
	
		use "$data/clean/cleaned_data.dta", clear
	
		global beta `beta'
		
		quietly {
		
		run "$code/modules/dtaxrate_calc.do"
		
		drop if borough == 5
		
		logit inclusionary_onsite dtaxrate_onsite $controls_lot $controls_block i.borough i.yearpermit, cl(nta)
		mat b = e(b)
		local coef_dtaxrate = b[1,1]
		
		predict xb, xb
		gen pr = exp(xb)/(1+exp(xb))
		
		gen pr_plus = exp(xb+`coef_dtaxrate'*0.001)/(1+exp(xb+`coef_dtaxrate'*0.001))
			
		gen assessprop = pr * ((assesstot - assessland)/(frac_assess*underassess)) * dtaxrate_onsite
		gen assessprop_plus = pr_plus * ((assesstot - assessland)/(frac_assess*underassess)) * (dtaxrate_onsite + 0.001)
		
		local sh_inclusionary = 0.20
		gen inclusionaryunits = `sh_inclusionary' * pr * unitsres
		gen inclusionaryunits_plus = `sh_inclusionary' * pr_plus * unitsres
		
		collapse (rawsum) assessprop assessprop_plus inclusionaryunits inclusionaryunits_plus (mean) pr pr_plus [aw=unitsres]
		
		gen mcostperunit = (assessprop_plus-assessprop)/(1000000*(inclusionaryunits_plus-inclusionaryunits))
		
		gen elast = 1000*(pr_plus - pr)
		
		summ mcostperunit
		local mcost = r(mean)
		
		summ elast
		local elast = r(mean)
		
		clear 
		
		set obs 1
		
		gen beta = `beta'
		gen mcost = `mcost'
		gen elast = `elast'
		
		append using `tmp'
		save `tmp', replace
	
		}
			
		di "`beta': MFC = `mcost', Response = `elast'"
		
	}
	
*** Make graphs
	
	use `tmp', clear
	
	format mcost %12.0fc
	
	gen drate = 1/beta - 1
	
	drop if drate < 0.005 | drate > 0.1
	
	format mcost %8.1f
	
	tw line mcost drate, ///
		graphregion(color(white)) xtitle("Capitalization Rate") ///
		ytitle("Cost Per Inclusionary Unit ($ Millions)") ylabel(,nogrid) 
		
	graph export "$figs/mcost_alt_drate.pdf", replace
	graph export "$figs_overleaf/mcost_alt_drate.pdf", replace
	
	tw line elast drate, ///
		graphregion(color(white)) xtitle("Capitalization Rate") ///
		ytitle("Response of Participation Rate to 421-a Incentive") ylabel(,nogrid) ///
		name(elast, replace)
			
	graph export "$figs/elast_alt_drate.pdf", replace
	graph export "$figs_overleaf/elast_alt_drate.pdf", replace		
